using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FreeLancer.HRB.Core;
using DevExpress.Web.ASPxMenu;

namespace FreeLancer.HRB.WebApp.Admin
{
  public partial class Admin : System.Web.UI.MasterPage
  {
    private const string SpecialistsRole = "Specialists";
    private const string AdministratorsRole = "Administrators";

    private string masterSelectedTab = string.Empty;
    public string MasterSelectedTab
    {
      get { return masterSelectedTab; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
      if (System.Threading.Thread.CurrentPrincipal.IsInRole(SpecialistsRole) &&
        !System.Threading.Thread.CurrentPrincipal.IsInRole(AdministratorsRole))
      {
        SetRole(SpecialistsRole);
      }

      if (!System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated)
      {
        Response.Redirect(Utils.RelativeWebRoot);
      }

      lblUserName.Text = System.Threading.Thread.CurrentPrincipal.Identity.Name;
    }

    protected void ASPxTabControl_TabClick(object source, DevExpress.Web.ASPxTabControl.TabControlCancelEventArgs e)
    {
      masterSelectedTab = e.Tab.Name;
      Response.Redirect("~/Admin/Pages/" + e.Tab.Name + ".aspx");
    }

    public void SetActiveTab(string tabName)
    {
      //ASPxTabControl.ActiveTab = ASPxTabControl.Tabs.FindByName(tabName);
    }

    private void SetRole(string role)
    {
      switch(role)
      {
        case SpecialistsRole:
          SetSpecialistsRole();
          break;
      }
    }

    private void SetSpecialistsRole()
    {
      ASPxMenu.Items.FindByName("Introducing").Visible = false;
      ASPxMenu.Items.FindByName("Foreword").Visible = false;
      ASPxMenu.Items.FindByName("Objective").Visible = false;
      ASPxMenu.Items.FindByName("List").Visible = false;
      ASPxMenu.Items.FindByName("Events").Visible = false;
      ASPxMenu.Items.FindByName("EditEvent").Visible = false;
      ASPxMenu.Items.FindByName("Ads").Visible = false;
      ASPxMenu.Items.FindByName("Users").Visible = false;
    }
  }
}
